home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacGofer 0.22d / MacGofer Sources / prelude.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-31  |  17.0 KB  |  502 lines  |  [TEXT/MPS ]

  1. /* --------------------------------------------------------------------------
  2.  * prelude.h:   Copyright (c) Mark P Jones 1991-1993.   All rights reserved.
  3.  *              See goferite.h for details and conditions of use etc...
  4.  *              Gofer version 2.28 January 1993
  5.  *
  6.  * Basic data type definitions, prototypes and standard macros including
  7.  * machine dependent variations...
  8.  * ------------------------------------------------------------------------*/
  9.  
  10. #define const          /* const is more trouble than it's worth,...       */
  11. #include <stdio.h>
  12.  
  13. /*---------------------------------------------------------------------------
  14.  * To select a particular machine/compiler, just place a 1 in the appropriate
  15.  * position in the following list and ensure that 0 appears in all other
  16.  * positions:
  17.  *
  18.  * The letters UN in the comment field indicate that I have not personally
  19.  * been able to test this configuration yet and I have not heard from anybody
  20.  * else that has tried it.  If you run Gofer on one of these systems and it
  21.  * works (or needs patches) please let me know so that I can fix it and
  22.  * update the source.
  23.  *-------------------------------------------------------------------------*/
  24.  
  25. #define TURBOC   0      /* For IBM PC, using Turbo C 1.5                */
  26. #define BCC     0      /* For IBM PC, using Borland C++ 3.1           */
  27. #define SUNOS    0      /* For Sun 3/Sun 4 running SunOs 4.x           */
  28. #define MIPS     0      /* For MIPS RC6280/Sony machine NWS-387           */
  29. #define NEXTSTEP 0      /* For NeXTstep 3.0 using NeXT cc ...           */
  30. #define NEXTGCC  0    /* For NeXTstep with gcc 2.x               */
  31. #define MINIX68K 0    /* For Minix68k with gcc            UN */
  32. #define AMIGA    0    /* For Amiga using gcc 2.2.2            UN */
  33. #define HPUX     0      /* For HPUX using gcc                UN */
  34. #define LINUX    0      /* For Linux using gcc                UN */
  35. #define DJGPP    0    /* For DJGPP version 1.09 (gcc2.2.2) and DOS 5.0   */
  36. #define ZTC      0    /* For IBM PC (>= 386) Zortech C++ v3.0 (-mx)       */
  37. #define RISCOS   0    /* For Acorn DesktopC and RISCOS2 or 3           */
  38. #define ALPHA     0    /* For DEC Alpha with OSF/1 (32 bit ints, no gofc) */
  39. #define OS2      0    /* For IBM OS/2 2.0 using EMX GCC           */
  40. #define SVR4     0    /* For SVR4 using GCC2.2               */
  41. #define ULTRIX   0      /* For DEC Ultrix 4.x using GCC2.3.3           */
  42. #define AIX     0    /* For IBM AIX on RS/6000 using GCC           */
  43. #define MPW      0    /* For Macintosh running under the MPW shell       */
  44. #define MAC     1    /* For a native Macintosh application           */
  45. #define THINKC   0    /* For Macintosh (native or tool) using Think C       */
  46.  
  47.  
  48. /*---------------------------------------------------------------------------
  49.  * To add a new machine/compiler, add a new macro line above, add the new
  50.  * to the appropriate flags below and add a `machine specific' section in the
  51.  * following section of this file.  Please send me details of any new machines
  52.  * or compilers that you try so that I can pass them onto others!
  53.  *
  54.  *   UNIX          if the machine runs fairly standard Unix
  55.  *   SMALL_GOFER   for 16 bit operation on a limited memory PC
  56.  *   REGULAR_GOFER for 32 bit operation using largish default table sizes
  57.  *   LARGE_GOFER   for 32 bit operation using larger default table sizes
  58.  *   JMPBUF_ARRAY  if jmpbufs can be treated like arrays.
  59.  *   DOS_IO        to use DOS style IO for terminal control
  60.  *   TERMIO_IO     to use Unix termio for terminal control
  61.  *   SGTTY_IO      to use Unix sgtty for terminal control
  62.  *   BREAK_FLOATS  to use two integers to store a float (or double)
  63.  *           if SMALL_GOFER, then you *must* use BREAK_FLOATS == 1
  64.  *           (assumes sizeof(int)==2, sizeof(float)==4).
  65.  *           Otherwise, assuming sizeof(int)==sizeof(float)==4,
  66.  *                 BREAK_FLOATS == 0 will give you floats  for floating pt,
  67.  *           BREAK_FLOATS == 1 will give you doubles for floating pt.
  68.  *   HAS_FLOATS       to indicate support for floating point
  69.  *   HAS_HYPERBOLICS  if the machine also has all the "hyperbolic" trig functions.
  70.  *              (should be true for anything with a decent C compiler!)
  71.  *   JMPBUF_ARRAY     if jmpbufs can be treated like arrays.
  72.  *   BIT_OPERATIONS   to allow bitwise primitives
  73.  *   DYNAMIC_STORAGE  to use variable-sized arrays for major memory settings
  74.  *   BIT_OPERATIONS   to define Hexadecimal primitives
  75.  *   DOT_DEFAULT      to use dots by default to display progress when loading
  76.  *-------------------------------------------------------------------------*/
  77.  
  78. #define UNIX            (SUNOS  | NEXTSTEP | HPUX | NEXTGCC | LINUX | AMIGA | \
  79.                  MINIX68K |ALPHA | OS2 | SVR4 | ULTRIX | AIX | MIPS )
  80. #define SMALL_GOFER     (TURBOC | BCC)
  81. #define REGULAR_GOFER   (RISCOS | DJGPP | ZTC | MAC | MPW)
  82. #define LARGE_GOFER     (UNIX   | ALPHA)
  83. #define JMPBUF_ARRAY    (UNIX   | DJGPP | RISCOS | ZTC | MAC | MPW )
  84. #define DOS_IO          (TURBOC | BCC | DJGPP | ZTC | MPW | MAC)
  85. #define TERMIO_IO       (LINUX  | HPUX | OS2 | SVR4)
  86. #define SGTTY_IO        (SUNOS  | NEXTSTEP | NEXTGCC | AMIGA | MINIX68K | \
  87.                          ALPHA  | ULTRIX | AIX | MIPS)
  88. #define BREAK_FLOATS    (TURBOC | BCC)
  89. #define HAS_FLOATS      (REGULAR_GOFER | LARGE_GOFER | BREAK_FLOATS)
  90. #define DYNAMIC_STORAGE    (REGULAR_GOFER | LARGE_GOFER)      /* Most recent PCs should also support this */ 
  91. #define BIT_OPERATIONS    1
  92. #define    DOT_DEFAULT    RISCOS
  93.  
  94. /*---------------------------------------------------------------------------
  95.  * The following flags should be set automatically according to builtin
  96.  * compiler flags, but you might want to set them manually to avoid default
  97.  * behaviour in some situations:
  98.  *-------------------------------------------------------------------------*/
  99.  
  100. #ifdef  __GNUC__            /* look for GCC 2.x extensions       */
  101. #if     __GNUC__ >= 2 && !NEXTSTEP    /* NeXT cc lies and says it's 2.x  */
  102. #define GCC_THREADED 1
  103.  
  104. /* WARNING: if you use the following optimisations to assign registers for
  105.  * particular global variables, you should be very careful to make sure that
  106.  * storage(RESET) is called after a longjump (usually resulting from an error
  107.  * condition) and before you try to access the heap.  The current version of
  108.  * main deals with this using everybody(RESET) at the head of the main read,
  109.  * eval, print loop
  110.  */
  111.  
  112. #ifdef  m68k                /* global registers on an m68k       */
  113. #define GLOBALcar    asm("a4")
  114. #define GLOBALcdr    asm("a5")
  115. #define GLOBALsp    asm("a3")
  116. #endif
  117.  
  118. #ifdef  sparc                /* global registers on a sparc       */
  119. /* sadly, although the gcc documentation suggests that the following reg   */
  120. /* assignments should be ok, experience shows (at least on Suns) that they */
  121. /* are not -- it seems that atof() and friends spoil things.           */
  122. /*#define GLOBALcar    asm("g5")*/
  123. /*#define GLOBALcdr    asm("g6")*/
  124. /*#define GLOBALsp    asm("g7")*/
  125. #endif
  126.  
  127. #endif
  128. #endif
  129.  
  130. #ifndef GCC_THREADED
  131. #define GCC_THREADED 0
  132. #endif
  133.  
  134. /*---------------------------------------------------------------------------
  135.  * Machine specific sections:
  136.  * Include any machine specific declarations and define macros:
  137.  *   local              prefix for locally defined functions
  138.  *   far                prefix for far pointers
  139.  *   allowBreak()       call to allow user to interrupt computation
  140.  *   FOPEN_WRITE        fopen *text* file for writing
  141.  *   FOPEN_APPEND       fopen *text* file for append
  142.  *
  143.  * Note: 'far' must be defined, but 'local' defaults to empty!
  144.  *
  145.  *-------------------------------------------------------------------------*/
  146.  
  147. #ifdef __STDC__           /* To enable use of prototypes whenever possible */
  148. #define Args(x) x
  149. #else
  150. #if (TURBOC | BCC | ZTC)  /* K&R 1 does not permit `defined(__STDC__)' ... */
  151. #define Args(x) x
  152. #else
  153. #define Args(x) ()
  154. #endif
  155. #endif
  156.  
  157. #if     (TURBOC | BCC)
  158. #include <alloc.h>
  159. #define local           near pascal
  160. extern  int  kbhit       Args((void));
  161. #define allowBreak()       kbhit()
  162. #define FOPEN_WRITE       "wt"
  163. #define FOPEN_APPEND       "at"
  164. #define farCalloc(n,s)       farcalloc((unsigned long)n,(unsigned long)s)
  165. #define sigProto(nm)       int nm(void)
  166. #define sigRaise(nm)       nm()
  167. #define sigHandler(nm)       int nm()
  168. #define sigResume       return 1
  169. #endif
  170.  
  171. #if     SUNOS
  172. #include <malloc.h>
  173. #define far
  174. #define farCalloc(n,s)       (Void *)valloc(((unsigned)n)*((unsigned)s))
  175. #endif
  176.  
  177. #if     MIPS
  178. #define far
  179. #define farCalloc(n,s)       (Void *)valloc(((unsigned)n)*((unsigned)s))
  180. #endif
  181.  
  182. #if     (NEXTSTEP | NEXTGCC | AMIGA | MINIX68K | ULTRIX)
  183. #include <stdlib.h>
  184. #define far
  185. #define farCalloc(n,s)       (Void *)valloc(((unsigned)n)*((unsigned)s))
  186. #endif
  187.  
  188. #if     (HPUX | DJGPP | ZTC | LINUX | ALPHA | OS2 | SVR4 | AIX)
  189. #include <stdlib.h>
  190. #define far
  191. #endif
  192.  
  193. #if    RISCOS
  194. #include <string.h>
  195. #include <stdlib.h>
  196. #include <signal.h>
  197. #define  far
  198. #define  isascii(c)    (((unsigned)(c))<128)
  199. #define  Main        int
  200. #define  MainDone    return 0;/*NOTUSED*/
  201. extern   int access    Args((char *, int));
  202. #endif
  203.  
  204.  
  205. /*
  206.     The changes for the Mac version are rather more extensive than for
  207.     other machines...  KH
  208. */
  209.  
  210. #if MAC
  211. #include <Types.h>
  212. #undef MPW
  213. #define MPW     1        /* The MPW changes are required for the Mac version.
  214.                    Think C is almost like MPW, so all MPW definitions
  215.                    apply to Think, unless commented out.
  216.                 */
  217.  
  218. #define EVT_ITERATIONS       400    /* Frequency to check for events during evaluation */
  219.  
  220. #if THINKC
  221. int mfprintf(FILE *, const char *, ...);
  222. int mprintf(const char *, ...);
  223. #endif
  224.  
  225. #define printf   mprintf    /* Redefine printf and fprintf(std*) to write to a window!! */
  226. #define fprintf  mfprintf
  227. #undef  getc
  228. #define getc     mgetc        /* getc, putc, etc also write to the worksheet */
  229. #undef  putc            /* or read from the keyboard for stdin/stdout/stderr */
  230. #define putc     mputc
  231. #define fputc    mputc
  232. #define fgetc    mgetc
  233. #define fflush     mflush
  234. #define malloc     safemalloc    /* A "safe" version of malloc with a nice alert */
  235. #define calloc     safecalloc    /* A "safe" version of calloc with a nice alert */
  236. #define exit     safeexit    /* A "graceful" exit function */
  237. #endif
  238.  
  239. #if MPW
  240. #define PROMPT               "Gofer?"    /* The default Gofer prompt */
  241. #define FOPEN_WRITE       "w"        /* fopen *text* file for writing   */
  242. #define FOPEN_APPEND       "a"        /* fopen *text* file for append       */
  243. #include "malloc.h"
  244.  
  245. #define far
  246. #define ctrlbrk(bh)    
  247. #endif
  248.  
  249. /*
  250.     Now define defaults for macros which haven't been defined above.
  251. */
  252.  
  253. #ifndef USE_READLINE
  254. #define USE_READLINE  0
  255. #endif
  256. #ifndef allowBreak
  257. #define allowBreak()
  258. #endif
  259. #ifndef local
  260. #define local
  261. #endif
  262. #ifndef farCalloc
  263. #define farCalloc(n,s)       (Void *)calloc(((unsigned)n),((unsigned)s))
  264. #endif
  265. #ifndef FOPEN_WRITE
  266. #define FOPEN_WRITE       "w"
  267. #endif
  268. #ifndef FOPEN_APPEND
  269. #define FOPEN_APPEND       "a"
  270. #endif
  271. #ifndef sigProto
  272. #define sigProto(nm)       Void nm Args((int))
  273. #define sigRaise(nm)       nm(1)
  274. #define sigHandler(nm)       Void nm(sig_arg) int sig_arg;
  275. #define sigResume       return
  276. #endif
  277.  
  278. #ifndef PROMPT
  279. #define    PROMPT      "? "    /* Default Gofer Prompt */
  280. #endif
  281.  
  282. #ifndef Main            /* to cope with systems that don't like       */
  283. #define Main           Void /* main to be declared as returning Void   */
  284. #endif
  285. #ifndef MainDone
  286. #define MainDone
  287. #endif
  288.   
  289. #if (UNIX | DJGPP | RISCOS | ZTC)
  290. #define ctrlbrk(bh)       signal(SIGINT,bh)
  291. #endif
  292.  
  293. /*---------------------------------------------------------------------------
  294.  * General settings:
  295.  *-------------------------------------------------------------------------*/
  296.  
  297. #define Void     void   /* older compilers object to: typedef void Void;   */
  298. #if !MPW
  299. typedef unsigned Bool;
  300. #else
  301. typedef int Bool;    /* NB: On the Mac, Bool != Boolean, TRUE != TRUE!  KH */
  302. #endif
  303.  
  304. #define TRUE     1
  305. #define FALSE    0
  306. typedef char    *String;
  307. typedef int      Int;
  308. typedef long     Long;
  309. typedef int      Char;
  310. typedef unsigned Unsigned;
  311.  
  312. #ifndef STD_PRELUDE
  313. #if     RISCOS
  314. #define STD_PRELUDE       "prelude"
  315. #else
  316. #define STD_PRELUDE       "standard.prelude"
  317. #endif
  318. #endif
  319.  
  320. #define NUM_SYNTAX         100
  321. #define NUM_SELECTS        100
  322. #define NUM_FILES       20
  323. #define NUM_MODULES        64
  324. #define NUM_FIXUPS         100
  325. #define NUM_TUPLES         100
  326. #define NUM_OFFSETS        1024
  327. #define NUM_CHARS          256
  328.  
  329. /* Managing two different sized versions of Gofer has caused problems in
  330.  * the past for people who tried to change one setting, but inadvertantly
  331.  * modified the settings for a different size.  Now that we have three
  332.  * sizes of Gofer, I think it's time to try a new scheme:
  333.  */
  334.   
  335. #if     SMALL_GOFER            /* the McDonalds mentality :-)       */
  336. #define Pick(s,r,l)       s
  337. #endif
  338. #if     REGULAR_GOFER
  339. #define Pick(s,r,l)       r
  340. #endif
  341. #if     LARGE_GOFER
  342. #define Pick(s,r,l)       l
  343. #endif
  344.   
  345. #define NUM_TYCON          Pick(60,    160,        160)
  346. #define NUM_NAME           Pick(625,   2000,       16000)
  347. #define NUM_CLASSES        Pick(20,    40,         40)
  348. #define NUM_INSTS          Pick(60,    100,        100)
  349. #define NUM_INDEXES        Pick(700,   2000,       2000)
  350. #define NUM_DICTS          Pick(400,   32000,      32000)
  351. #define NUM_TEXT           Pick(7000,  20000,      80000)
  352. #define NUM_TEXTH       Pick(1,     10,         10)
  353. #define NUM_TYVARS         Pick(800,   3000,       4000)
  354. #define NUM_STACK          Pick(1800,  16000,      16000)
  355. #define NUM_ADDRS          Pick(28000, 100000,     320000)
  356. #define MINIMUMHEAP       Pick(7500,  7500,       7500)
  357. #define MAXIMUMHEAP       Pick(32765, 0,          0)
  358. #define DEFAULTHEAP        Pick(28000, 100000,     100000)
  359. #define MAXPOSINT          Pick(32767, 2147483647, 2147483647)
  360.   
  361. #define minRecovery       Pick(1000,  1000,       1000)
  362. #define bitsPerWord       Pick(16,    32,         32)
  363. #define wordShift       Pick(4,     5,          5)
  364. #define wordMask       Pick(15,    31,         31)
  365.  
  366. #define bitArraySize(n)    ((n)/bitsPerWord + 1)
  367. #define placeInSet(n)      ((-(n)-1)>>wordShift)
  368. #define maskInSet(n)       (1<<((-(n)-1)&wordMask))
  369.  
  370.  
  371. /* For Hex numbers, define the largest Int value to be all ones */
  372. #define MAXUNSIGNEDINT     (~0)
  373.  
  374. /*    
  375.     None of the defaults is quite right for a 2M Mac, so they have to 
  376.     be modified here.
  377.     
  378.     Since the user can set these from within the application, making them
  379.     smaller by default isn't a big deal.  This is also true for any
  380.     version compiled with DYNAMIC_STORAGE.
  381. */
  382.  
  383. #if     MPW
  384. #undef    NUM_NAME
  385. #define NUM_NAME           1000
  386. #undef    NUM_DICTS
  387. #define NUM_DICTS          16000
  388. #undef    NUM_TEXT
  389. #define NUM_TEXT           16384
  390. #undef    NUM_TYVARS
  391. #define NUM_TYVARS         2000
  392. #undef    NUM_STACK
  393. #define NUM_STACK          8000
  394. #undef    NUM_ADDRS
  395. #define NUM_ADDRS          60000
  396. #endif
  397.  
  398. #if DYNAMIC_STORAGE
  399. extern int    num_tycon, tyconhsz, num_syntax, name_hsz,
  400.         num_name, num_classes, num_stack,
  401.         num_text, texthsz, num_indexes, num_insts,
  402.         num_addrs, num_dicts, num_tuples, num_offsets,
  403.         num_selects, num_tyvars, num_fixups,
  404.         num_files, num_modules;
  405.  
  406. #else    /* Define contants equal to the above variables */
  407.  
  408. #define num_tycon      NUM_TYCON
  409. #define num_syntax     NUM_SYNTAX
  410. #define    num_name     NUM_NAME
  411. #define    num_classes     NUM_CLASSES
  412. #define    num_stack     NUM_STACK
  413. #define    num_modules     NUM_MODULES
  414. #define    num_files     NUM_FILES
  415. #define    num_text     NUM_TEXT
  416. #define    num_indexes     NUM_INDEXES
  417. #define    num_insts     NUM_INSTS
  418. #define    num_tuples    NUM_TUPLES
  419. #define    num_offsets    NUM_OFFSETS
  420. #define    num_selects    NUM_SELECTS
  421. #define    num_addrs    NUM_ADDRS
  422. #define num_dicts    NUM_DICTS
  423. #define num_tyvars    NUM_TYVARS
  424. #define num_fixups    NUM_FIXUPS
  425. #endif
  426.  
  427. #ifndef __GNUC__
  428. #if !RISCOS
  429. extern Int      strcmp     Args((String, String));
  430. extern Int      strlen     Args((String));
  431. extern char    *strcpy       Args((String,String));
  432. extern char     *strcat       Args((String,String));
  433. #endif
  434. #endif
  435. extern char    *getenv       Args((char *));
  436. extern int      system       Args((const char *));
  437. extern double   atof       Args((char *));
  438. extern char     *strchr    Args((char *,int));  /* test membership in str  */
  439. extern Void     exit       Args((Int));
  440. extern Void     internal   Args((String));
  441. extern Void     fatal       Args((String));
  442.  
  443.  
  444. /*
  445.     Note:     gcCStack() will screw up badly if sizeof(float/double) != sizeof(Cell)
  446.         and floating point values are passed by value.  This is pretty
  447.         gross since "random" memory errors will occur.  This can happen if
  448.         IEEE-488 extended precision (80-bit) values are used, for example.
  449.  
  450.         If you don't know what your compiler does, either don't use 
  451.         gcCStack(), don't use float, or redefine Floating point code
  452.         as for the Macintosh.  KH
  453. */
  454.  
  455. #if     HAS_FLOATS
  456. #ifdef  NEED_MATH
  457. #include <math.h>
  458. #endif
  459. #if !MPW
  460. #if    (REGULAR_GOFER | LARGE_GOFER) & BREAK_FLOATS
  461. #define FloatImpType       double
  462. #define FloatPro       double
  463. #define FloatFMT           "%.9g"
  464. #else
  465. #define FloatImpType       float
  466. #define FloatPro       double  /* type to use in prototypes           */
  467.                    /* strictly ansi (i.e. gcc) conforming  */
  468.                    /* but breaks data hiding :-(       */
  469. #define FloatFMT       "%g"
  470. #endif
  471.  
  472. #else
  473. #define FloatImpType       Cell    /* Wierd things happen if these are not */
  474. #define FloatPro       Cell    /* the same size as Cells! KH       */
  475. #define FloatFMT       "%g"
  476. #endif
  477.  
  478. #else
  479. #define FloatImpType       int     /*dummy*/
  480. #define FloatPro       int
  481. #define FloatFMT       "%d"
  482. #endif
  483.  
  484. #ifndef FILENAME_MAX       /* should already be defined in an ANSI compiler*/
  485. #define FILENAME_MAX 256
  486. #else
  487. #if     FILENAME_MAX < 256
  488. #undef  FILENAME_MAX
  489. #define FILENAME_MAX 256
  490. #endif
  491. #endif
  492.  
  493. #if UNIX
  494. #define DEF_EDITOR       "vi"            /* replace with ((char *)0)*/
  495. #define DEF_EDITLINE       "vi +%d %s"        /* if no default editor rqd*/
  496. #else
  497. #define DEF_EDITOR       ((char *) 0)    
  498. #define DEF_EDITLINE       ((char *) 0)
  499. #endif
  500.  
  501. /*-------------------------------------------------------------------------*/
  502.